﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Saber.Plugin.NtfsSearch
{
    /// <summary>
    /// NtfsSearchSettings.xaml 的交互逻辑
    /// </summary>
    public partial class NtfsSearchSettings : UserControl
    {
        private PluginInitContext context;
        private Settings _settings;
        private readonly Loading loading;


        public NtfsSearchSettings(PluginInitContext context, Settings settings, SettingsViewModel viewModel,Loading loading)
        {
            this.context = context;
            InitializeComponent();
            _settings = settings;
            this.loading = loading;
            DataContext = viewModel;

            
        }

        private void BtnSuffixes_OnClick(object sender, RoutedEventArgs e)
        {
            Suffixes p = new Suffixes(context, _settings);
            p.ShowDialog();
        }


        private void BtnReload_Click(object sender, RoutedEventArgs e)
        {
            loading.Load();
        }

        private void BtnReloadSet_Click(object sender, RoutedEventArgs e)
        {
            if (loading.IsLoading)
            {
                MessageBox.Show("后台正在检索，请检索完成后重试！");
                return;
            }
            Button b = (Button)sender;

            if (_settings.Paths.Contains(b.ToolTip.ToString()))
            {
                MessageBoxResult r = MessageBox.Show(string.Format("取消 {0} 检索，并重新检索！",b.ToolTip.ToString()), "提示 ", MessageBoxButton.OKCancel);
                if (r == MessageBoxResult.OK)
                {
                    _settings.Paths.Remove(b.ToolTip.ToString());
                    loading.Load();
                }
            }
            else
            {
                MessageBoxResult r = MessageBox.Show(string.Format("添加 {0} 检索，并重新检索！", b.ToolTip.ToString()), "提示 ", MessageBoxButton.OKCancel);
                if (r == MessageBoxResult.OK)
                {
                    _settings.Paths.Add(b.ToolTip.ToString());
                    loading.Load();
                }
            }

        }
    }
}
